# -*- coding: utf-8 -*-
'''
Created on 2019/11/12 11:39 
author:dyx
IDE:PyCharm 
'''

'''
创建schoolMen类
该类中包含三种属性：姓名、性别、年龄
以及针对每个属性的get和set方法
'''
#基类
class SchoolMen(object):
    def __init__(self,name='',sex='female',age=20):
        # 定义实例属性
        self.setName(name)
        self.setSex(sex)
        self.setAge(age)
    def getName(self):
        return self.__name
    def getSex(self):
        return self.__sex
    def getAge(self):
        return self.__age
    def setName(self,name):
        if not isinstance(name,str):
            print('name must be string.')
            return
        self.__name = name
    def setSex(self,sex):
        if sex != 'male' and sex != 'female':
            print('sex must be "male" or "female".')
            return
        self.__sex = sex
    def setAge(self,age):
        if not isinstance(age,int):
            print('age must be integer.')
            return
        self.__age = age
    def printInfo(self):
        print('name:',self.__name)
        print('sex:',self.__sex)
        print('age:',self.__age)

'''
创建Student类，继承自SchoolMem类
添加额外三个属性：班级、学号和数量统计
'''
#派生类
class Student(SchoolMen):
    def __init__(self,name='',sex='male',age = 0,cls='',id=0,cnt=0):
        super(Student,self).__init__(name,sex,age)
        self.setSex(sex)
        self.setCls(cls)
        self.setId(id)
        self.setCnt(cnt)

    def setCls(self,cls):
        if not isinstance(cls,str):
            print('class must be a string')
        self.__cls = cls

    def setId(self,id):
        if not isinstance(id,int):
            print('class must be integer')
        self.__id = id

    def setCnt(self, cnt):
        if not isinstance(cnt, int):
            print('cnt must be integer')
        self.__cnt = cnt

    def printInfo(self):
        super(Student,self).printInfo()
        print('class:', self.__cls)
        print('id:',self.__id)
        print('number:', self.__cnt)

'''
创建Teacher类，继承自SchoolMem类，
添加额外三个属性：科室、工号和数量统计
'''
# 要求在Student类和Teacher类中分别实现printInfo方法，该方法打印对象的多有属性信息

class Teacher(SchoolMen):
    def __init__(self,name='ddd',age=23,sex='male',dept = 'software',tid = 1,cnt = 1):
        SchoolMen.__init__(self,name,sex,age)
        self.setDept(dept)
        self.setId(tid)
        self.setCnt(cnt)

    def setDept(self,dept):
        if not isinstance(dept,str):
            print('dept must be string')
            return
        self.__dept = dept

    def setId(self,tid):
        if not isinstance(tid,int):
            print('id must be integer')
            return
        self.__tid = tid

    def setCnt(self,cnt):
        if not isinstance(cnt,int):
            print('number must be integer')
            return
        self.__cnt = cnt

    def printInfo(self):
        super(Teacher,self).printInfo()
        print('department:',self.__dept)
        print('id:',self.__tid)
        print('number',self.__cnt)


if __name__ == '__main__':
    #基类SchoolMen功能测试
    schoolmen = SchoolMen('dqq','female',21)
    print('打印基类SchoolMen实例对象的所有信息:')
    schoolmen.printInfo()
    print('测试基类的get方法:')
    print('schoolmen name:',schoolmen.getName())
    print('schoolmen sex:', schoolmen.getSex())
    print('schoolmen age:',schoolmen.getAge())
    print('测试基类的set方法:')
    schoolmen.setAge(18)
    print('new schoolmen age:', schoolmen.getAge())
    schoolmen.setName('dongqiaqia')
    print('new schoolmen name:', schoolmen.getName())
    schoolmen.setSex('male')
    print('new schoolmen sex:',schoolmen.getSex())
    print('打印更新后的基类的所有信息:')
    schoolmen.printInfo()
    #派生类Student功能测试
    student = Student('ddd','male',22,'software1704',17407111402,1)
    print('打印派生类Student实例对象的所有信息:')
    student.printInfo()
    #派生类Teacher功能测试
    teacher = Teacher('dyx',26,'female','software',10,1)
    print('打印派生类Teacher实例对象的所有信息:')
    teacher.printInfo()


